package com.ewhale.feitengguest.presenter.shop.task

import com.ewhale.feitengguest.api.ApiHelper
import com.ewhale.feitengguest.dto.EditTaskDto
import com.ewhale.feitengguest.dto.ShopTaskDto
import com.ewhale.feitengguest.dto.ShopWalletDto
import com.ewhale.feitengguest.view.shop.release.ReleaseTaskView
import com.ewhale.feitengguest.view.shop.task.IncreasePayView
import com.ewhale.feitengguest.view.shop.task.STaskView
import com.simga.library.base.IPresenter
import com.simga.library.http.APIException
import java.util.*

/**
 * 作者：SimGa
 * 日期：2020/2/26
 * 时间：13:54
 * 包名：com.ewhale.feitengguest.presenter.shop.task
 */
class IncreasePayPresenter : IPresenter() {
    //涨价 余额付款
    val increasePriceByWallet = "app/shop/addUnitPriceMissionOrderPayByWallet.json"
    //涨价   第三方付款
    val increasePriceByThird = "app/shop/addUnitPriceMissionOrderCreate.json"
    //添加名额 余额付款
    val increaseNumberByWallet = "app/shop/addJoinNumMissionOrderPayByWallet.json"
    //添加名额   第三方付款
    val increaseNumberByThird = "app/shop/addJoinNumMissionOrderCreate.json"

    fun getShopWallet() {
        mView.showProLoading()
        request(1, ApiHelper.USER_API.shopWalletAndStatus, null)
    }

    fun payTaskByWallet(type: Int, number: Int, price: String,missionId:Long) {
        mView.showProLoading()
        val params = HashMap<String,Any>()
        params["id"] = missionId
        if (type == 1001) {
            params["addUnitPrice"] = price
            request(2, ApiHelper.TASK_API.increaseWallet(increasePriceByWallet,params), null)
        } else {
            params["addJoinNum"] = number
            request(2, ApiHelper.TASK_API.increaseWallet(increaseNumberByWallet,params), null)
        }
    }

    fun payTaskByThird(payType: Int, type: Int, number: Int, price: String,missionId:Long) {
        mView.showProLoading()
        val params = HashMap<String,Any>()
        params["id"] = missionId
        params["payType"] = payType
        if (type == 1001) {
            params["addUnitPrice"] = price
            request(3, ApiHelper.TASK_API.increaseThirdPay(increasePriceByThird,params), null)
        } else {
            params["addJoinNum"] = number
            request(3, ApiHelper.TASK_API.increaseThirdPay(increaseNumberByThird,params), null)
        }
    }

    override fun <T : Any?> onNext(postCode: Int, result: T, data: Any?) {
        super.onNext(postCode, result, data)
        when (postCode) {
            1 -> (mView as IncreasePayView).showWallet(result as ShopWalletDto)
            2 -> (mView as IncreasePayView).paySuccess()
            3 -> (mView as IncreasePayView).goToThirdPay(result as Any)
        }
    }

    override fun otherException(postCode: Int, data: Any?, e: APIException?) {
        super.otherException(postCode, data, e)
        mView.showErrorMessage(postCode, e!!.code, e.displayMessage)
    }
}
